package com.liumingtai.demo01.upload.controller;

import com.liumingtai.demo01.common.utils.R;
import com.liumingtai.demo01.modules.email.service.UploadService;
import com.liumingtai.demo01.upload.config.WebConfigProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RefreshScope
@RequestMapping("/upload")
public class UploadController {

    @Autowired
    WebConfigProperties webConfigProperties;

    @Autowired
    UploadService uploadService;


    @GetMapping(" ")
    public String index() {
        return "hello, email there";
    }


    @GetMapping("/configTest")
    public String config1() {
        return webConfigProperties.getDesc();
    }


    @PostMapping("/uploadImage")
    @ResponseBody
    public R uploadImage(@RequestParam("file") MultipartFile file) throws IOException {
        String s = uploadService.uploadImage(file.getOriginalFilename(), file.getInputStream());
        return R.ok("上传成功").put("path", s);
    }

}
